﻿@{
    ViewBag.Title = "通知消息";
    ViewBag.PathToBtn = "/Message/List";
    ViewBag.TextBtn = "刷新";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <a id="btnSetRead" href="javascript:;" class="btn btn-success">一键已读</a>
            </div>
        </div>
    </div>
</div>

<!-- /.row -->
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                通知消息
            </div>
            <!-- /.panel-heading -->
            <div class="panel-body">
                <div class="dataTable_wrapper">
                    <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                            <tr>
                                <th>接收时间</th>
                                <th>标题</th>
                                <th>内容</th>
                                <th>是否已读</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>                           
                        </tbody>
                    </table>
                </div>
                <!-- /.table-responsive -->
            </div>
            <!-- /.panel-body -->
        </div>
        <!-- /.panel -->
    </div>
    <!-- /.col-lg-12 -->
</div>
<!-- /.row -->

@section javascript{
    <script src="/Content/admin/dist/js/pagingHelper.js"> </script>
    <script type="text/javascript">
        var dataParams = {};
        var serverProcessPath = "/Message/Listing";
        var showColumns = [
            { data: "Created" },
            { data: "Title" },
            { data: "Body" },
            { data: "IsRead" },
            { data: "Action" }
        ];
        var redefineColumns = [{
            targets: 0,
            render: function (data, type, full, meta) {
                return GFC.formatJsonDate(data);
            }
        },
        {
            targets: 3,
            render: function (data, type, full, meta) {
                return "未读";
            }
        }];
        pagingHelper.Paging(serverProcessPath, dataParams, showColumns, redefineColumns);

        $("#ContentHeadBtn").click(function () {
            pagingHelper.reload();
        });
        
        $('#btnSetRead').click(function () {
            alertify
                .okBtn("确定")
                .cancelBtn("取消")
                .confirm("确定全部设置为已读？", function () {
                    $.ajax({
                        type: 'post',
                        async: false,
                        url: '/Message/SetAllRead',
                        data: {},
                        success: function (result) {
                            if (result) {
                                alertify.success("设置成功");
                                setTimeout("pagingHelper.reload();", 500);
                            } else {
                                alertify.error("设置失败");
                            }
                        }
                    });
                }, function () {
                    // user clicked "cancel"
                });

        });

        function deleteData(id) {
            alertify
                .okBtn("确定")
                .cancelBtn("取消")
                .confirm("确定要删除该数据吗？", function () {
                    $.ajax({
                        type: 'post',
                        async: false,
                        url: '/Message/Delete',
                        data: { doIds: id },
                        success: function (result) {
                            if (result == true) {
                                alertify.success("数据删除成功");
                                setTimeout("pagingHelper.reload(); getLatestMsg();", 500);
                            } else if (result == false) {
                                alertify.error("数据删除失败");
                            } else {
                                alertify.error("无删除权限");
                            }
                        }
                    });
                }, function () {
                    // user clicked "cancel"
                }); 
        }
        
        function viewOrder(id, ordestatus) {
            window.location = "/Orders/Detail?id=" + id + "&orderStatus=" + ordestatus;
        }
    </script>
}